package net.example.lesson3.cglib;


import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author 肖红亮
 * @date 2018/9/11
 * @since JDK1.7
 */
public class MyMethodInterceptor implements MethodInterceptor {

    /**
     * CGLIB代理的切入点.
     *
     * @param obj 生成的代理对象
     * @param method 被代理对象方法
     * @param arg 方法入参
     * @param methodProxy 代理方法
     */
    @Override
    public Object intercept(Object obj, Method method, Object[] arg, MethodProxy methodProxy) throws Throwable {
        System.out.println("Before:" + method);
        Object object = methodProxy.invokeSuper(obj, arg);
        System.out.println("After:" + method);
        return object;
    }
}
